﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows.Forms;



namespace FXnaGis
{


    /// <summary>
    /// 需要注意的是，由于我们重写了鼠标的关键事件参数，所以对外提供参数时，要求坐标统一转换geo
    /// </summary>
    [Serializable]
    public abstract class FMapFunction
    {

        ///// <summary>
        ///// Occurs during a mouse down event
        ///// </summary>
        //public event EventHandler<MouseEventArgs> MouseDown;

        ///// <summary>
        ///// Occurs during a mouse move event
        ///// </summary>
        //public event EventHandler<MouseEventArgs> MouseMove;

        ///// <summary>
        ///// Occurs during a mouse up event
        ///// </summary>
        //public event EventHandler<MouseEventArgs> MouseUp;

        ///// <summary>
        ///// Occurs during a mousewheel event
        ///// </summary>
        //public event EventHandler<MouseEventArgs> MouseWheel;

        ///// <summary>
        ///// Occurs during a double click event
        ///// </summary>
        //public event EventHandler<MouseEventArgs> MouseDoubleClick;

        ///// <summary>
        ///// Occurs during a key up event
        ///// </summary>
        //public event EventHandler<KeyEventArgs> KeyUp;


        public FMapFunction(FMapFrame frame)
        {

            this._geoMapFrame = frame;

            this._enabled = true;
 
        }



        protected bool _alwaysOn = false;

        public  bool AlwaysOn
        {
            get { return _alwaysOn; }
            set { _alwaysOn = value; }
        }




        protected bool _enabled;

        public bool Enabled
        {
            get { return _enabled; }

            //暂时不允许外围设置
            protected  set { _enabled = value; }
        }

        protected FMapFrame _geoMapFrame;


        #region Methods

        /// <summary>
        /// Instructs this tool to
        /// </summary>
        /// <param name="e"></param>
        public void DoKeyUp(KeyEventArgs e)
        {
            OnKeyUp(e);
        }

        /// <summary>
        /// Forces this tool to execute whatever behavior should occur during a double click even on the panel
        /// </summary>
        /// <param name="e"></param>
        public void DoMouseDoubleClick(MouseEventArgs e)
        {
            OnMouseDoubleClick(e);
        }

        /// <summary>
        /// Instructs this tool to perform any actions that should occur on the MouseDown event
        /// </summary>
        /// <param name="e">A MouseEventArgs relative to the drawing panel</param>
        public void DoMouseDown(MouseEventArgs e)
        {
            OnMouseDown(e);
        }

        /// <summary>
        /// Instructs this tool to perform any actions that should occur on the MouseMove event
        /// </summary>
        /// <param name="e">A MouseEventArgs relative to the drawing panel</param>
        public void DoMouseMove(MouseEventArgs e)
        {
            OnMouseMove(e);
        }

        /// <summary>
        /// Instructs this tool to perform any actions that should occur on the MouseUp event
        /// </summary>
        /// <param name="e">A MouseEventArgs relative to the drawing panel</param>
        public void DoMouseUp(MouseEventArgs e)
        {
            OnMouseUp(e);
        }

        /// <summary>
        /// Instructs this tool to perform any actions that should occur on the MouseWheel event
        /// </summary>
        /// <param name="e">A MouseEventArgs relative to the drawing panel</param>
        public void DoMouseWheel(MouseEventArgs e)
        {
            OnMouseWheel(e);
        }

        /// <summary>
        /// This is the method that is called by the drawPanel.  The graphics coordinates are
        /// in pixels relative to the image being edited.
        /// </summary>
        public void Draw(FMapDrawArgs args)
        {
            //if (OnBeforeDrawing(args) == true) return; // handled
            OnDraw(args);
        }

       

        /// <summary>
        /// Cancels whatever drawing was being done by the tool and resets the cursor to an arrow.
        /// </summary>
        public virtual void Cancel()
        {
        }



        /// <summary>
        /// This allows sub-classes to customize the drawing that occurs.  All drawing is done
        /// in the image coordinate space, where 0, 0 is the upper left corner of the image.
        /// </summary>
        /// <param name="e">A PaintEventArgs where the graphics object is already in image coordinates</param>
        protected virtual void OnDraw(FMapDrawArgs e)
        {
        }

        /// <summary>
        /// fires the KeyUp event
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnKeyUp(KeyEventArgs e)
        {
            //if (KeyUp == null)
            //{
            //    return;
            //}
            //KeyUp(this, e);
        }


        public void DoKeyDown(KeyEventArgs e)
        {
            OnKeyDown(e);
        }



        /// <summary>
        /// Occurs when a key is pressed
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnKeyDown(KeyEventArgs e)
        {
        }


        /// <summary>
        /// Fires the DoubleClick event
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnMouseDoubleClick(MouseEventArgs e)
        {
        //    if (MouseDoubleClick == null)
        //    {
        //        return;
        //    }
        //    MouseDoubleClick(this, e);
        }

        /// <summary>
        /// fires the MouseDown event
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnMouseDown(MouseEventArgs e)
        {
        //    if (MouseDown == null)
        //    {
        //        return;
        //    }
        //    MouseDown(this, e);
        }

        /// <summary>
        /// allows for inheriting tools to control OnMouseMove
        /// </summary>
        /// <param name="e">A GeoMouseArgs parameter</param>
        protected virtual void OnMouseMove(MouseEventArgs e)
        {
            //if (MouseMove == null)
            //{
            //    return;
            //}
            //MouseMove(this, e);
        }

        /// <summary>
        /// Fires the MouseUP event
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnMouseUp(MouseEventArgs e)
        {
            //if (MouseUp == null)
            //{
            //    return;
            //}
            //MouseUp(this, e);
        }

        /// <summary>
        /// Allows for inheriting tools to override the behavior
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnMouseWheel(MouseEventArgs e)
        {
            //if (MouseWheel == null)
            //{
            //    return;
            //}
            //MouseWheel(this, e);
        }

        #endregion

        #region 功能函数

        /// <summary>
        /// Forces activation
        /// </summary>
        public void Activate()
        {
            OnActivate();
        }

        /// <summary>
        /// Deactivate is like when someone clicks on a different button.  It may not
        /// involve the whole plugin being unloaded.
        /// </summary>
        public void Deactivate()
        {
            OnDeactivate();
        }


        /// <summary>
        /// This is fired when enabled is set to true, and firing this will set enabled to true
        /// </summary>
        protected virtual void OnActivate()
        {
            _enabled = true;

           
        }

        /// <summary>
        /// 关闭功能
        /// </summary>
        protected virtual void OnDeactivate()
        {
            _enabled = false;
           

        }



        #endregion



    }
}
